package com.heima.comment.controller;

import com.heima.comment.pojo.ApCommentDto;
import com.heima.comment.pojo.ApLikesDto;
import com.heima.comment.service.ApCommentService;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.comment.dtos.CommentDto;
import com.heima.model.comment.dtos.CommentLikeDto;
import com.heima.model.comment.dtos.CommentSaveDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class LylCommentController {
    @Autowired
    ApCommentService apCommentService;

    /**
     * 文章评论-评论
     * 保存评论
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/save")
    public ResponseResult commentSave(@RequestBody CommentSaveDto dto){
        apCommentService.commentSave(dto);
        return ResponseResult.ok();
    }

    /**
     * 文章评论-评论
     * 查询评论列表
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/load")
    public ResponseResult<List<ApCommentDto>> commentLoad(@RequestBody CommentDto dto){
        List<ApCommentDto> result =   apCommentService.commentLoad(dto);
        return ResponseResult.ok(result);
    }

    /**
     * 文章评论-评论
     * 点赞
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/like")
    public ResponseResult<ApLikesDto> commentLike(@RequestBody CommentLikeDto dto){
        ApLikesDto apLikesDto = apCommentService.commentLike(dto);
        return ResponseResult.ok(apLikesDto);
    }
}
